<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        form {
            width: 460px;
            height: 550px;
            background-color: blueviolet;
            position: relative;
            margin: auto;
        }

        input[type="text"] {
            height: 40px;
            width: 250px;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
            outline: none;
        }

        input[type="password"] {
            height: 40px;
            width: 250px;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
            outline: none;
        }

        .username {
            top: 50px;
        }

        .password {
            top: 110px;
        }

        .tel {
            top: 170px;
        }

        .sex {
            width: 250px;
            position: absolute;
            top: 240px;
            left: 50%;
            transform: translateX(-50%);
        }

        button {
            width: 140px;
            height: 50px;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
            background-color: deeppink;
        }

        .logon {
            top: 300px;
        }

        .login {
            top: 370px;
        }
        .check {
            position: absolute;
            top: 60px;
            right: 20px;
            font-size: 12px;
        }
    </style>
    <script src="https://cdn.staticfile.net/jquery/1.10.2/jquery.min.js"></script>
</head>

<body>
<form action="logon" method="post">
    <input type="text" name="username" placeholder="姓名" class="username"><span class="check"></span>
    <input type="password" name="password" placeholder="密码" class="password">
    <input type="text" name="tel" placeholder="电话号码" class="tel">
    <div class="sex">
        性别:
        <input type="radio" name="sex" value="男">男
        <input type="radio" name="sex" value="女">女
    </div>
    <button type="submit" class="logon">注册</button>
    <a href="login.html"><button class="login">登录</button></a>
</form>

<script>
    $(function(){
        $(".username").blur(function(){
            if(!$(".username").val()){
                $(".check").html("用户名不能为空").css("color","#e93854")
                $(".logon").prop("disabled",true)
            }else{
                $.ajax({
                    type:"POST",
                    url:"/checkname",
                    data: {
                        "username":$(".username").val()
                    },
                    success:function (check){
                        if (check=="true"){
                            $(".check").html("用户名已存在").css("color","#e93854")
                            $(".logon").prop("disabled",true)
                        }else{
                            $(".check").html("用户名可以使用").css("color","black")
                            $(".logon").prop("disabled",false)
                        }
                    }
                })
            }
        })
    })
</script>
</body>

</html>